//
//  UITextField.swift
//  fho
//
//  Created by 郭颢源 on 2021/3/31.
//

import Foundation
import UIKit

private var key: Void?
extension UITextField {
    // runtime 为系统的类添加属性
    var bcTextIndex: IndexPath? {
        get {
            return objc_getAssociatedObject(self, &key) as? IndexPath
        }
        set(newValue) {
            objc_setAssociatedObject(self, &key, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
    }
  
    ///
    /// Set the placeholder color of UITextField
    ///
    /// - parameter color: Placeholder color
    ///
    func sg_setPlaceholder(color: UIColor) {
        guard let tempPlaceholder = self.placeholder else { return }
        let attributes = [NSAttributedString.Key.foregroundColor: color]
        let attributedString = NSAttributedString(string: tempPlaceholder, attributes: attributes)
        self.attributedPlaceholder = attributedString
    }
    
    
}
